package com.meilishuo.message.controller;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

import com.meilishuo.message.entity.common.DateEditor;
import com.meilishuo.message.exceptions.AccessException;



public class BaseController {

	
	/**
	 * 获取我存在session中的id
	 * @param request
	 * @return
	 * @throws AccessException
	 */
	protected Integer getMyIdInWeb(HttpServletRequest request) throws AccessException {
		try {
			
			if(request.getSession().getAttribute("userId") != null){
				return ((Integer)request.getSession().getAttribute("userId"));
			}else{
				return null;
			}
			
		} catch (Exception e) {
			throw new AccessException("请先登录"); 
		}
	}

	
	@InitBinder  
	protected void initBinder(HttpServletRequest request,  
	                              ServletRequestDataBinder binder) throws Exception {  
	    //对于需要转换为Date类型的属性，使用DateEditor进行处理  
	    binder.registerCustomEditor(Date.class, new DateEditor());  
	} 

}
